package com.zhifa.hdtyg_cdgl.service;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhifa.hdtyg_cdgl.dao.SiteInformationMapper;
import com.zhifa.hdtyg_cdgl.dao.SiteUserTestMapper;
import com.zhifa.hdtyg_cdgl.entity.SiteInformation;
import com.zhifa.hdtyg_cdgl.entity.SiteUserTest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class SiteInformationService {

    @Autowired
    SiteInformationMapper siteInformationMapper;

    @Autowired
    SiteUserTestMapper siteUserTestMapper;

    @Autowired
    SiteUserTestService siteUserTestService;


    /**
     * 根据分页来查询当前所有场地信息
     * @param siteInformation
     * @param page
     * @return
     */

   /* public Object findAllSiteInformations(int pageNum,int pageSize){

        PageHelper.startPage(1,10);
        List<SiteInformation> list=siteInformationMapper.findAllSiteInformations();
        PageInfo<SiteInformation>pageInfo=new PageInfo<SiteInformation>(list);
        return JSONObject.toJSONString(pageInfo);
    }*/
   @Transactional
   public PageInfo<SiteInformation> findAllSiteInformation(SiteInformation siteInformation,int page,int rows){

       PageHelper.startPage(page, rows);

       List<SiteInformation> list=siteInformationMapper.findAllSiteInformation(siteInformation);

         for (int i = 0; i < list.size(); i++) {
          /* *
            * 通过id获取用户信息


           *
            * 设置前端显示的名字
            */
            // String nameById = siteUserTestMapper.findNameById(list.get(i).getAdminId());
             String nameById = siteUserTestService.findManagerNameById(list.get(i).getAdminId());

             list.get(i).setAdminName(nameById);

       }
       PageInfo<SiteInformation>pageInfo=new PageInfo<>(list);
       return pageInfo;
   }

        /**
         *     List<String> findName();
         *
         *     List<String> findPosition();
         *
         *     List<String> findPurpose();
         *
         *     List<String> findStatus();
         */
        public List<String> findName(){
            return siteInformationMapper.findName();

        }
        public List<String> findPosition(){
            return siteInformationMapper.findPosition();

        }
        public List<String> findPurpose(){
            return  siteInformationMapper.findPurpose();
        }
        public List<String> findStatus(){
            return  siteInformationMapper.findStatus();
        }

        /**
         *添加场地信息
         * @param siteInformation
         * @return
         */
        public int addSiteInfo(SiteInformation siteInformation){ return   siteInformationMapper.insert(siteInformation); }

        public int modifyInfo(SiteInformation siteInformation){

           return siteInformationMapper.updateByPrimaryKey(siteInformation);

        }

        public SiteInformation findSiteInformationBySiteId(Integer id){
            return siteInformationMapper.selectByPrimaryKey(id);

        }
        public int updateStatusWeixiu(Map<String,Object>map){
            return siteInformationMapper.updateStatusWeixiu(map);
        }

}
